package ControlLayer;
import ModelLayer.Employee;
import ModelLayer.EmployeeContainer;
import ModelLayer.Customer;
import ModelLayer.CustomerContainer;
/**
 * Person controller:
 * Connects PersonUI, CustomerUI and EmployeeUI to the model layer.
 * 
 * @author Gruppe 3
 * @version 1.0
 */
public class PersonCtr
{
    private EmployeeContainer employeeContainer;
    private CustomerContainer customerContainer;
    
    /**
     * constructor
     */
    public PersonCtr()
    {   
        customerContainer = CustomerContainer.getInstance();
        employeeContainer = EmployeeContainer.getInstance();
    }
    
    /**
     * Adds a customer to the ArrayList customers
     * @param name          name of the customer to be added
     * @param address       address of the customer to be added
     * @param phone         phone of the customer to be added
     * @param email         email of the customer to be added
     * @param customerID    id of the customer to be added
     * @param discount      discount of the customer to be added
     * @param cvrNr         CVR number of the customer to be added
     */   
    public void addCustomer(String name, String address, String phone, String email, String customerID, double discount, String cvrNr)
    {   
        try
        {
            customerContainer.addCustomer(name, address, phone, email, customerID, discount, cvrNr);   
        }
        catch(NullPointerException e)
        {
            System.out.println("Der skete en fejl, da systemet prøvede at oprette en ny kunde");
        }
    }
    
    /**
     * Finds and returns a customer 
     * @param searchID 
     * @return found customer
     */    
    public Customer getCustomer(String searchID)
    {   
        try 
        {
            return customerContainer.getCustomer(searchID);
        }
        catch(NullPointerException e)
        {
            System.out.println("Den ansatte kunne ikke findes i systemet");
        }
        
        return null;
    }
    
    /**
     * Finds a customer in the ArrayList customers
     * @param searchID
     */    
    public void findCustomer(String searchID)
    {   
        try 
        {
            customerContainer.findCustomer(searchID);
        }
        catch(NullPointerException e )
        {
            System.out.println("Den ansatte ikke findes i systemet");
        }
    }
    
    /**
     * Deletes a customer in ArrayList customers
     * @param ID  id of the wanted customer to be deleted
     */    
    public void deleteCustomer(String searchID)
    {   
        try
        {
            customerContainer.deleteCustomer(searchID);
            System.out.println("Kunden blev slettet");
        }
        catch(NullPointerException e)
        {
            System.out.println("Den ansatte kunne ikke findes i systemet og kunne derfor ikke slettes");
        }
      
    }
    
    /**
     * Updates a customer in the ArrayList customers
     * @param name          name of the customer to be updated
     * @param address       address of the customer to be updated
     * @param phone         phone of the customer to be updated
     * @param email         email of the customer to be updated
     * @param customerID    id of the customer to be updated
     * @param discount      discount of the customer to be updated
     * @param cvrNr         CVR number of the customer to be updated
     * @param ID            old id of the customer to be updated
     */
    public void updateCustomer(String name, String address, String phone, String email, 
                               String customerID, double discount, String cvrNr, String ID)
    {   
        try
        {
            customerContainer.updateCustomer(name, address, phone, email, customerID, discount, cvrNr, ID);
        }
        catch(NullPointerException e)
        {
            System.out.println("Der skete en fejl, da systemet prøvede at opdatere kunden");
        }
    }
    
    /**
     * prints a customer's fields as output to console
     * @param ID  id of the customer to be printed
     */
    public void listCustomer(String searchID)
    {   
        try
        {
            customerContainer.listCustomer(searchID);
        }
        catch(NullPointerException e)
        {
            System.out.println("Der skete en fejl, da systemet prøvede at printe information om kunden");
        }
    }

    /**
     * list all customers in the ArrayList customers
     */    
    public void listAllCustomers()
    {   
        try
        {
            customerContainer.listAllCustomers();
        }
        catch(NullPointerException e)
        {
            System.out.println("Der skete en fejl, da systemet prøvede at printe de registered kunder i systemet");
        }
    }
    
    /**
     * Add an employee to the ArrayList employees
     * 
     * @param name          name of the employee to be added
     * @param address       address of the employee to be added
     * @param phone         phone of the employee to be added
     * @param email         email of the employee to be added
     * @param employeeID    id of the employee to be added    * 
     */     
    public void addEmployee(String name, String address, String phone, String email, String employeeID)
    {  
        try
        {
            employeeContainer.addEmployee(name, address, phone, email, employeeID);   
        }
        catch(NullPointerException e)
        {
            System.out.println("Der skete en fejl, da systemet prøvede at oprette den nye ansatte");
        }
    }
    
    /**
     * Find and return a wanted employee in the ArrayList employees
     * 
     * @param searchID  id of the wanted person to return
     * @return found employe, otherwise null
     */    
    public Employee getEmployee(String searchID)
    {   
        try
        {
            return employeeContainer.getEmployee(searchID);
        }
        catch(NullPointerException e)
        {
            System.out.println("System kunne finde den ansatte i systemet");
        }
        
        return null;
    }
    
    /**
     * Finds an employee in the ArrayList employees
     * 
     * @param searchID  id of the wanted employee
     */
    public void findEmployee(String searchID)
    {   
        try
        {
            employeeContainer.findEmployee(searchID);
        }
        catch(NullPointerException e)
        {
            System.out.println("Den ansatte kunne ikke findes i systemet");
        }
    }
    
    /**
     * Deletes an employee in the ArrayList employees
     */
    public void deleteEmployee(String searchID)
    {   
        try
        {
            employeeContainer.deleteEmployee(searchID);
            System.out.println("Den ansatte blev slettet");
        }
        catch(NullPointerException e)
        {
            System.out.println("Der skete en fejl, da systemet prøvede at slette den ansatte");
        }
    }
    
    /**
     * Updates an employee in the ArrayList employees
     */
    public void updateEmployee(String name, String address, String phone, String email, String employeeID, String ID)
    {   
        try
        {
            employeeContainer.updateEmployee(name, address, phone, email, employeeID, ID);
        }
        catch(NullPointerException e)
        {
            System.out.println("System kunne ikke opdatere den ansatte");
        }
    }
    
    /**
     * Find and list an employee in the ArrayList employees
     * @param employeeID  id of the wanted employee
     */    
    public void listEmployee(String searchID)
    {   
        try
        {
            employeeContainer.listEmployee(searchID);
        }
        catch(NullPointerException e)
        {
            System.out.println("Der skete en fejl, da systemet kunne ikke printe information om den ansatte");
        }
    }

    /**
     * List all employees in the ArrayList employees
     */    
    public void listAllEmployees()
    {   
        try
        {
            employeeContainer.listAllEmployees();
        }
        catch(NullPointerException e)
        {
            System.out.println("Der skete en fejl, da systemet prøvede at printe de registered ansatte i systemet");
        }
    }     
}